package com.travel.dao;

import com.travel.domain.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersDao {


    @Select("select * from orders")
    @Results({
          @Result(column = "id",property = "id"),
          @Result(column = "ordernum",property = "orderNum"),
          @Result(column = "orderTime",property = "orderTime"),
          @Result(column = "orderStatus",property = "orderStatus"),
          @Result(column = "peopleCount",property = "peopleCount"),
          @Result(column = "payType",property = "payType"),
          @Result(column = "orderDesc",property = "orderDesc"),
           @Result(column = "productId" ,property = "product" ,one = @One(select="com.travel.dao.ProductDao.findById"))
    })
    List<Orders> findAll();
    @Select("select count(*) from orders")
    Integer findAllCount();

    @Select("select * from orders where id =#{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "ordernum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "productId" ,property = "product" ,one = @One(select="com.travel.dao.ProductDao.findById")),
            @Result(column = "memberId" ,property = "member", one = @One(select = "com.travel.dao.MemberDao.findByMemberId")),
            @Result(column = "id",property = "travellers",many = @Many(select ="com.travel.dao.TravellerDao.findByOrdersId" ))
    })
    Orders findByOrderId(String id);


}
